﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Scheduler.Data_Access_Layer
{
    /**Class: Employee
    * @author Daniel Chopson
    * @version 1.0
    * Course : ITEC 4860 Spring 2012
    * Written: March 22, 2012
    *
    * This class connects to the Employee and User tables in the database via
    * TableAdapters. Getters and setters are provided for employees.
    *
    * Purpose: To provide the data access neccessary for modifying employee
    * accounts in the Employee Listing and Employee Profile modules.
    */

    class Employee
    {
        //The employee's ID

        private string empUserID;

        //The adapter for Employee table connectivity

        private SchedulerTableAdapters.EmployeeTableAdapter employeeAdapter;

        //The data table for temporarily holding employee data

        private Scheduler.EmployeeDataTable employeeData;

        //A single row from the Employee table

        private Scheduler.EmployeeRow employeeRow;

        //The adapter for User table connectivity

        private SchedulerTableAdapters.UserTableAdapter userAdapter;

        //The data table for temporarily holding user data

        private Scheduler.UserDataTable userData;

        /** Method: Employee
          * Constructor for this class. Instantiates all class variables
          * @param empUserID the employee's ID
          */

        public Employee(string empUserID)
        {
            this.empUserID = empUserID;
            employeeAdapter = new SchedulerTableAdapters.EmployeeTableAdapter();
            employeeData = employeeAdapter.GetData();
            userAdapter = new SchedulerTableAdapters.UserTableAdapter();
            userData = userAdapter.GetData();
        }

        /** Method: getAllEmployees
          * Gets all of the fields for a given row
          * @return an ArrayList of database fields
          */

        public ArrayList getAllEmployees()
        {
            ArrayList empArray = new ArrayList();
            foreach (Scheduler.UserRow userRow in userData)
            {
                foreach (Scheduler.EmployeeRow empRow in employeeData)
                {
                    if (userRow.UserID.Trim() == empRow.EmpUserID.Trim())
                    {
                        ArrayList temp = new ArrayList();
                        temp.Add(empRow.EmpUserID);
                        temp.Add(userRow.Name);
                        temp.Add(userRow.Phone);
                        temp.Add(userRow.Email);
                        empArray.Add(temp);
                    }
                }
            }
            return empArray;
        }

        /** Method: getAllEmployeeIDs
          * Gets all of the fields for a given row
          * @return an ArrayList of database fields
          */

        public ArrayList getAllEmployeeIDs()
        {
            ArrayList empArray = new ArrayList();
            foreach (Scheduler.EmployeeRow empRow in employeeData)
            {
                empArray.Add(empRow.EmpUserID.Trim());
            }
            return empArray;
        }

        /** Method: locateEmployee
          * Locates the row in the Employee table with the specified employee ID
          * Note: Must be called before the methods following it can be used
          * @return a boolean to denote whether the employee was found
          */

        public bool locateEmployee()
        {
            employeeData = employeeAdapter.GetDataByEmpID(empUserID);
            if (employeeData.Count == 0)
            {
                return false;
            }
            else
            {
                employeeRow = employeeData[0];
            }
            return true;
        }

        /** Method: getPayRate
          * Gets the employee's pay rate
          * @return PayRate from the Employee table
          */

        public Decimal getPayRate()
        {
            return employeeRow.PayRate;
        }

        /** Method: setPayRate
          * Sets the employee's pay rate
          * @param payRate the employee's pay rate
          */

        public void setPayRate(Decimal payRate)
        {
            employeeRow.PayRate = payRate;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getHireDate
          * Gets the employee's hire date
          * @return HireDate from the Employee table
          */

        public DateTime getHireDate()
        {
            return employeeRow.HireDate;
        }

        /** Method: setHireDate
          * Sets the employee's hire date
          * @param hireDate the employee's hire date
          */

        public void setHireDate(DateTime hireDate)
        {
            employeeRow.HireDate = hireDate;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getEmpComment
          * Gets the employee's comment
          * @return EmpComment from the Employee table
          */

        public string getEmpComment()
        {
            return employeeRow.EmpComment.Trim();
        }

        /** Method: setEmpComment
          * Sets the employee's comment
          * @param empComment the employee's comment
          */

        public void setEmpComment(string empComment)
        {
            employeeRow.EmpComment = empComment;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getMgrComment
          * Gets the manager's comment
          * @return MgrComment from the Employee table
          */

        public string getMgrComment()
        {
            return employeeRow.MgrComment.Trim();
        }

        /** Method: setMgrComment
          * Sets the manager's comment
          * @param mgrComment the manager's comment
          */

        public void setMgrComment(string mgrComment)
        {
            employeeRow.MgrComment = mgrComment;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getEmpMinWeeklyHrs
          * Gets the employee's preference for minimum weekly hours
          * @return EmpMinWeeklyHrs from the Employee table
          */

        public int getEmpMinWeeklyHrs()
        {
            return employeeRow.EmpMinWeeklyHrs;
        }

        /** Method: setEmpMinWeeklyHrs
          * Sets the employee's preference for minimum weekly hours
          * @param empMinWeeklyHrs the employee's preference for minimum weekly hours
          */

        public void setEmpMinWeeklyHrs(int empMinWeeklyHrs)
        {
            employeeRow.EmpMinWeeklyHrs = empMinWeeklyHrs;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getEmpMaxWeeklyHrs
          * Gets the employee's preference for maximum weekly hours
          * @return EmpMaxWeeklyHrs from the Employee table
          */

        public int getEmpMaxWeeklyHrs()
        {
            return employeeRow.EmpMaxWeeklyHrs;
        }

        /** Method: setEmpMaxWeeklyHrs
          * Sets the employee's preference for maximum weekly hours
          * @param empMaxWeeklyHrs the employee's preference for maximum weekly hours
          */

        public void setEmpMaxWeeklyHrs(int empMaxWeeklyHrs)
        {
            employeeRow.EmpMaxWeeklyHrs = empMaxWeeklyHrs;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getMgrMinWeeklyHrs
          * Gets the manager's preference for minimum weekly hours
          * @return MgrMinWeeklyHrs from the Employee table
          */

        public int getMgrMinWeeklyHrs()
        {
            return employeeRow.MgrMinWeeklyHrs;
        
        }

        /** Method: setMgrMinWeeklyHrs
          * Sets the manager's preference for minimum weekly hours
          * @param mgrMinWeeklyHrs the manager's preference for minimum weekly hours
          */

        public void setMgrMinWeeklyHrs(int mgrMinWeeklyHrs)
        {
            employeeRow.MgrMinWeeklyHrs = mgrMinWeeklyHrs;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getMgrMaxWeeklyHrs
          * Gets the manager's preference for maximum weekly hours
          * @return MgrMaxWeeklyHrs from the Employee table
          */

        public int getMgrMaxWeeklyHrs()
        {
            return employeeRow.MgrMaxWeeklyHrs;
        }

        /** Method: setMgrMaxWeeklyHrs
          * Sets the manager's preference for maximum weekly hours
          * @param mgrMaxWeeklyHrs the manager's preference for maximum weekly hours
          */

        public void setMgrMaxWeeklyHrs(int mgrMaxWeeklyHrs)
        {
            employeeRow.MgrMaxWeeklyHrs = mgrMaxWeeklyHrs;
            employeeAdapter.Update(employeeData);
        }

        /** Method: getPreferencesLastUpdated
          * Gets the employee's last preference update date
          * @return PreferencesLastUpdated from the Employee table
          */

        public string getPreferencesLastUpdated()
        {
            return employeeRow.PreferencesLastUpdated;
        }

        /** Method: setPreferencesLastUpdated
          * Sets the employee's last preference update date
          * @param preferencesLastUpdated the employee's last preference update date
          */

        public void setPreferencesLastUpdated(string preferencesLastUpdated)
        {
            employeeRow.PreferencesLastUpdated = preferencesLastUpdated;
            employeeAdapter.Update(employeeData);
        }
    }
}